package cn.lingnan.mapper;

import cn.lingnan.annotation.AutoFill;
import cn.lingnan.pojo.dto.*;
import cn.lingnan.pojo.entity.*;
import cn.lingnan.pojo.entity.Property;
import cn.lingnan.pojo.vo.*;
import cn.lingnan.utils.OperationType;
import com.github.pagehelper.Page;
import org.apache.ibatis.annotations.*;

import java.time.LocalDateTime;
import java.util.List;

@Mapper
public interface UserMapper {
    Page<Property> getAll(UserPageQueryAllDTO userPageQueryAllDTO);


    Page<Property> getSecondhand(UserPageSecendHandDTO userPageSecendHandDTO);

    PropertyVO getPropertyById(Integer propertyId);

    Page<Property> getLikeProperty(UserPageLikeDTO userPageLikeDTO);

//    @Insert("INSERT INTO property.favorite (user_id, property_id,favorite_date) VALUES (#{userId}, #{propertyId},#{favoriteDate})")
    Integer saveFavorite(Favorite favorite);

//    @Insert( "INSERT INTO property.transaction_info (user_id, property_id, amount, transaction_date,status) VALUES (#{userId}, #{propertyId},#{amount},#{transactionDate},#{status})" )
    Integer saveTransaction(Transaction transaction);

    List<TransactionVO> getTransactionByUserId(Long userId, Integer type);

    @Delete("DELETE FROM property.transaction_info WHERE Transaction_id = #{transactionId}")
    Integer deleteTransactionById(Long transactionId);

    @Select( "SELECT * FROM property.user_info WHERE user_id = #{userId}" )
    UserVO getUserById(Long userId);

    @Update( "UPDATE property.user_info SET avatar = #{url} WHERE user_id = #{userId}")
    void updateUserImage(Long userId, String url);


    void updateUser(UserDTO userDTO);

    List<ReviewVO > getReviewByPropertyId(Integer propertyId);

    @Insert( "INSERT INTO property.review_info(property_id, user_id, rating, comment, review_date) VALUES (#{propertyId}, #{userId}, #{rating}, #{comment}, #{reviewDate})")
    void saveReview(Review review);

    List<FavoriteVO> getFavoriteByUserId(Long userId);

    @Delete("DELETE FROM property.favorite WHERE favorite_id = #{favoriteId}")
    void deleteFavoriteById(Long favoriteId);

    @AutoFill(value= OperationType.INSERT)
    void saveMyPostProperty(Property property);

    @Select("SELECT * FROM property.property_info WHERE landlord_id = #{userId}")
    List<MyPropertyVO> getMyPostProperty(Long userId);

    @Update("UPDATE property.property_info SET status = #{status}, update_time = #{updateTime} WHERE property_id = #{propertyId}")
    void StartOrStop(Long propertyId, Integer status, LocalDateTime updateTime);

    List<BookingVO> getBookingsByUserId(Long userId);

    @Insert("INSERT INTO property.booking (booking_id, property_id, booking_time, remark_info, user_id) VALUES (#{bookingId}, #{propertyId}, #{bookingTime}, #{remarkInfo}, #{userId})")
    void saveBooking(Booking booking);

    @Delete("DELETE FROM property.booking WHERE booking_id = #{bookingId}")
    void deleteBookingById(Long bookingId);
}
